<template>
  <div class="extend-score">
    <div class="extend-label">继承抽检</div>
    <el-select
      v-model="relationTask"
      filterable
      clearable
      :disabled="disabled"
      style="width: 400px;"
      placeholder="请选择需要继承的管理动作"
      @change="selectGldz"
    >
      <el-option
        v-for="item in gldzList"
        :key="item.fid"
        :label="item.label"
        :value="item.fid"
      />
    </el-select>
  </div>
</template>

<script>
import {
  getPreviousGldz
} from '@/api/projectInspection/courseCheck'
export default {
  name: 'ExtendScore',
  data() {
    return {
      loading: false,
      gldzList: [],
      // 查询参数
      queryParams: {
        projectId: undefined,
        processType: undefined,
        randomType: undefined // 检查单位
      },
      specialTypes: [],
      disabled: false,
      relationTask: ''
    }
  },
  created() { // 初始化
    this.getDicts('cq_process_type').then(response => {
      this.specialTypes = response.data
    })
  },
  mounted() {
  },
  methods: {
    init(obj) {
      if (obj.processType === 'civil') {
        obj.processType = 'handcover'
      } else {
        obj.processType = 'civil'
      }
      Object.assign(this.queryParams, obj)
      this.relationTask = obj.relationTask
      if (this.relationTask) {
        this.disabled = true
      } else {
        this.disabled = false
      }
      this.getList()
    },
    getList() {
      this.loading = true
      getPreviousGldz(this.queryParams).then(
        response => {
          if (response.code === 200) {
            this.gldzList = response.data.map(item => {
              let processName = ''
              this.specialTypes.forEach(type => {
                if (type.dictValue === item.processType) {
                  processName = type.dictLabel
                }
              })
              return {
                ...item,
                label: `${processName || ''} / ${item.principalUserName || ''} / ${item.checkDate} / 【${item.gldzScore}分】`
              }
            })
            for (let i = 0; i < this.gldzList.length; i++) {
              if (this.gldzList[i].fid === this.relationTask) {
                this.$emit('extendScore', this.gldzList[i])
              }
            }
          }
        }
      ).finally(() => {
        this.loading = false
      })
    },
    selectGldz() {
      let row = {}
      for (let i = 0; i < this.gldzList.length; i++) {
        if (this.gldzList[i].fid === this.relationTask) {
          row = this.gldzList[i]
        }
      }
      this.$emit('extendScore', row)
    }
  }
}
</script>

<style scoped lang='scss'>
 .extend-score {
   display: flex;
   align-items: center;
   .extend-label {
     color: #606266;
     width: 70px;
     font-size: 14px;
   }
 }
</style>
